#include "Widget.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent)
{
    setupUi(this);
    /*QProcess **/myProcess = new QProcess(this);
    connect(myProcess, SIGNAL(finished(int)), this, SLOT(finishedProcess(int)));
}

void Widget::on_btnClose_clicked()
{
    close();
}

void Widget::on_btnPlay_clicked()
{
    /*
    qDebug() << "play";
    QString program = "/usr/bin/play";  /// ubuntu 13.04 :~$ whereis play
    QStringList arguments;
    arguments << "/usr/share/sounds/gnome/default/alerts/glass.ogg";

    QProcess *myProcess = new QProcess(this);
    myProcess->start(program, arguments);
    if (!myProcess->waitForFinished())
        qDebug() << false;
    else
        qDebug() << true;
        */
    /*bool b = */playSound();
    qDebug() << "on_btnPlay_clicked";
}

void Widget::finishedProcess(int code)
{
    if (code == QProcess::NormalExit)
        qDebug() << "ok!!!";
    else
        qDebug() << "bad!!!";
}

void Widget::playSound()
{
//    bool retorna;
    qDebug() << "playSound";
    QString program = "/usr/bin/play";  /// ubuntu 13.04 :~$ whereis play
    QStringList arguments;
    arguments << "/usr/share/sounds/gnome/default/alerts/glass.ogg";


    myProcess->start(program, arguments);
    /// function wait that bin finish the process
//    if (!myProcess->waitForFinished())
//        retorna = false;
//    else
//        retorna = true;
    qDebug() << "finished playSound";
//    return retorna;
}
